import { useFetch } from "@vueuse/core";
import type { UseFetchOptions } from "@vueuse/core";
import { computed, ref } from "vue";
export const baseURL = (import.meta as any).env.VITE_BASE_URL;
const options: UseFetchOptions = {
  immediate: false,
  beforeFetch(ctx) {
    if (ctx.url === "") {
      ctx.cancel();
    }
  },
  afterFetch(ctx) {
    return ctx.data;
  },
};
export function useFeatchSearch() {
  const id = ref("");
  const url = computed(() => {
    if (id.value === "") {
      return "";
    }
    return baseURL + `/no-auth/bible/search?query=${id.value}`;
  });
  const { data, error, isFetching, abort, canAbort, execute } = useFetch(url, options).get().json();
  return {
    data,
    error,
    isFetching,
    abort,
    canAbort,
    id,
    execute,
  };
}
